package tlcn.app;

import java.util.ArrayList;
import java.util.List;

import com.keyes.youtube.OpenYouTubePlayerActivity;

import tlcn.business.ManagerData;
import tlcn.data.Material;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;


public class GuideActivity extends Activity{
	LinearLayout l;
	Button play;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide_dishes);
		l=(LinearLayout) findViewById(R.id.tabVideo);
		loadTab();
		 
l.setOnClickListener(new OnClickListener() {
			//http://www.youtube.com/watch?v=x7BiGpvOLqw
			//http://www.youtube.com/watch?v=WOv2Vfd1QtM
			@Override
			public void onClick(View v) {
					Intent lVideoIntent = new Intent(null, Uri
							.parse("ytv://"+"WOv2Vfd1QtM"),
							GuideActivity.this,
							OpenYouTubePlayerActivity.class);
					startActivity(lVideoIntent);
			}
		});
	}
	
	private void loadTab(){
		final TabHost tab=(TabHost) findViewById (android.R.id.tabhost);
		tab.setup();
		TabHost.TabSpec spec;
		//Tạo tab1
		spec=tab.newTabSpec("t1");
		spec.setContent(R.id.tabMaterials);
		spec.setIndicator("Materials");
		tab.addTab(spec);
		doWidgetsTab1();
		//Tạo tab2
		spec=tab.newTabSpec("t2");
		spec.setContent(R.id.tabGuide);
		spec.setIndicator("Guide");
		tab.addTab(spec);
		//Tạo tab3
		spec=tab.newTabSpec("t3");
		spec.setContent(R.id.tabVideo);
		spec.setIndicator("Video");
		tab.addTab(spec);
		TextView tv= (TextView) findViewById(R.id.txtDishName);
		tv.setText(getIntent().getExtras().getString("DishID"));
	}
	private void doWidgetsTab1(){
		ManagerData data= new ManagerData(this);
		ArrayList<Material> materials = data.getMaterialOfDish(getIntent().getExtras().getString("DishID"));
		List<String> list= new ArrayList<String>();
		for (Material m : materials) {
			list.add(m.getWeight()+m.getUnit()+" "+m.getMaterialName());
		}
		ListView listViewDish= (ListView) findViewById(R.id.listViewDish);
		ArrayAdapter<String> adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
		listViewDish.setAdapter(adapter);
	}

	
}
